import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:oktoast/oktoast.dart';
import 'package:sjx/route/route_observer.dart';
import 'package:sjx/route/route_utils.dart';
import 'package:sjx/route/routes.dart';

/// 设计尺寸
Size get designSize {
  final firstView = WidgetsBinding.instance.platformDispatcher.views.first;
  // 逻辑短边
  final logicalShortestSide = firstView.physicalSize.shortestSide / firstView.devicePixelRatio;
  // 逻辑长边
  final logicalLongestSide = firstView.physicalSize.longestSide / firstView.devicePixelRatio;
  // 缩放比例 designSize越小，元素越大
  const scaleFactor = 0.95;
  // 缩放后的逻辑短边和长边
  return Size(logicalShortestSide * scaleFactor, logicalLongestSide * scaleFactor);
}

class MyApp extends StatelessWidget {

  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {

    //toast提示必须为APP的顶层组件
    return OKToast(
        child: ScreenUtilInit(
          designSize: designSize,
          builder: (context, child) {
            return MaterialApp(
              navigatorObservers: [routeObserver],
              theme: ThemeData(
                  useMaterial3: true,
                  colorScheme: ColorScheme.light(
                  primary: Color.fromRGBO(255, 75, 85, 1)
                )
              ),
              navigatorKey: RouteUtils.navigatorKey,
              onGenerateRoute: Routes.generateRoute,
              initialRoute: RoutePath.tab,
            );
          },
        )
    );
  }

}